<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="css/maintable.css"/>
    <link rel="stylesheet" type="text/css" href="css/edittable.css"/>
    <link rel="stylesheet" type="text/css" href="css/validate.css"/>
    <script type="text/javascript" src="js/jquery-1.8.0.js"></script>
    <script>
        $(function () {
            var list =${menuIds};
            $("input[type=checkbox]").each(function () {
                for (var i = 0; i < list.length; i++) {
                    if (list[i] == this.value) {
                        this.checked = true;
                    }
                }
            });
            $("input[id=parent]").click(function () {
                var arr = $(this).parent().next().children();
                for (var i = 0; i < arr.length; i++) {
                    arr[i].checked = this.checked;
                }
            });
            $("input[id=children]").click(function () {
                var child = $(this).siblings();
                var flag = 0;
                if (this.checked == true) {
                    flag = flag + 1;
                }
                for (var i = 0; i < child.length; i++) {
                    if (child[i].checked === true) {
                        flag = flag + 1;
                    }
                }
                var parent = $(this).parent().prev().children();

                if (flag == 0) {
                    parent[0].checked = false;
                } else {
                    parent[0].checked = true;
                }
            })
        });

    </script>
</head>
<body>
<div class="div_title">
    <div class="div_titlename"><img src="images/san_jiao.gif"><span>角色授权  当前角色:${roleInfo.roleName}</span></div>
    <div class="div_titleoper"></div>
</div>
<form action="RoleServlet.do" method="post">
    <input type="hidden" name="roleId" value="${roleInfo.id}">
    <input type="hidden" name="flag" value="updateRoleMenu">
    <table class="main_table">
        <tr>
            <th>一级菜单</th>
            <th>二级菜单</th>
        </tr>

        <c:forEach var="menu" items="${menuList}">
            <tr>
                <td>
                    <input type="checkbox" name="ids" id="parent" value="${menu.id}">${menu.menuName}_${menu.id}
                </td>

                <td>
                    <c:forEach items="${menu.subMenuList}" var="m_sub">
                        <input type="checkbox" name="ids" id="children"
                               value="${m_sub.id}">${m_sub.menuName}_${m_sub.id} <br/>
                    </c:forEach>
                </td>
            </tr>
        </c:forEach>
    </table>
    <input class="form_btn" id="form_btn" type="submit" value="提交"/>
    <input type="reset" class="form_btn" value="重置"/></td>
    <label id="result_msg" class="result_msg">${msg}</label>
</form>

</body>
</html>
